home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / xceedzip / ZIPMANAG.BAS < prev    next >
Encoding:
BASIC Source File  |  1999-04-26  |  8.2 KB  |  206 lines

  1. Attribute VB_Name = "modZipManager"
  2. Option Explicit
  3.  
  4. ' Constants used by the sample application to determine
  5. ' the characteristics of Open Dialog
  6.  
  7. Public Const OpenZip = 0
  8. Public Const NewZip = 1
  9. Public Const SelectBin = 5
  10. Public Const ChooseFiles = 6
  11.  
  12. ' Constants used to determine the command executed by the
  13. ' ExecuteSelFilesCmd function
  14.  
  15. Public Const SF_Delete = 0
  16. Public Const SF_Extract = 1
  17.  
  18. '------------------------------------------------------------------------------------
  19. ' This function returns a string representing the files attributes. It's used in
  20. ' the listing of an zip file's content in the main window.
  21. '------------------------------------------------------------------------------------
  22. Public Function Attributes(lAttr As Long) As String
  23.     Dim sRes As String
  24.     
  25.     If (lAttr And xfaArchive) > 0 Then sRes = sRes + "A" Else sRes = sRes + "-"
  26.     If (lAttr And xfaCompressed) > 0 Then sRes = sRes + "C" Else sRes = sRes + "-"
  27.     If (lAttr And xfaFolder) > 0 Then sRes = sRes + "D" Else sRes = sRes + "-"
  28.     If (lAttr And xfaHidden) > 0 Then sRes = sRes + "H" Else sRes = sRes + "-"
  29.     If (lAttr And xfaReadOnly) > 0 Then sRes = sRes + "R" Else sRes = sRes + "-"
  30.     If (lAttr And xfaSystem) > 0 Then sRes = sRes + "S" Else sRes = sRes + "-"
  31.     If (lAttr And xfaVolume) > 0 Then sRes = sRes + "V" Else sRes = sRes + "-"
  32.     
  33.     Attributes = sRes
  34. End Function
  35.  
  36. '------------------------------------------------------------------------------------
  37. ' This function counts the number of files in the list of files
  38. ' of the type returned by the SelectFilesToProcess function.
  39. '------------------------------------------------------------------------------------
  40. Public Function CountFilesInList(ByVal FileList As String) As Integer
  41.    Dim Count As Integer
  42.    Dim Pos As Integer
  43.    
  44.    Count = 0
  45.    For Pos = 1 To Len(FileList)
  46.       If Mid$(FileList, Pos, 1) = Chr(0) Then Count = Count + 1
  47.    Next Pos
  48.    
  49.    If Count = 0 Then Count = 1
  50.    
  51.    CountFilesInList = Count
  52. End Function
  53.  
  54. '------------------------------------------------------------------------------------
  55. ' This function takes a list of files of the type that is returned by
  56. ' the SelectFilesToProcess function, and returns a single file (with
  57. ' pathname).
  58. '------------------------------------------------------------------------------------
  59.  
  60. Public Function GetFileFromList(ByVal FileList As String, FileNumber As Integer) As String
  61.    Dim Pos As Integer
  62.    Dim Count As Integer
  63.    Dim FNStart As Integer
  64.    Dim FNLen As Integer
  65.    Dim Path As String
  66.  
  67.    If InStr(FileList, Chr(0)) = 0 Then
  68.       GetFileFromList = FileList
  69.    Else
  70.       Count = 0
  71.       Path = Left(FileList, InStr(FileList, Chr(0)) - 1)
  72.       If Right(Path, 1) <> "\" Then Path = Path + "\"
  73.       FileList = FileList + Chr(0) 'Addition de Chr(0) a la place de ""
  74.       For Pos = 1 To Len(FileList)
  75.          If Mid$(FileList, Pos, 1) = Chr(0) Then
  76.             Count = Count + 1
  77.             If Count = FileNumber Then FNStart = Pos + 1
  78.             If Count = (FileNumber + 1) Then
  79.                FNLen = Pos - FNStart
  80.                Exit For
  81.             End If
  82.          End If
  83.       Next Pos
  84.       GetFileFromList = Path + Mid(FileList, FNStart, FNLen)
  85.    End If
  86. End Function
  87.  
  88. '------------------------------------------------------------------------------------
  89. ' Identify the files read in the windows Dialog box. The window Dialog box
  90. ' returns a string of paths separated by a NULL caracter
  91. '------------------------------------------------------------------------------------
  92. Public Function IdentifyFiles(Files As String) As String
  93.     Dim FileNum As Integer
  94.     Dim ListFiles As String
  95.     Dim FileName As String
  96.  
  97.     For FileNum = 1 To CountFilesInList(Files)
  98.              FileName = GetFileFromList$(ByVal Files, FileNum)
  99.              ListFiles = ListFiles + FileName + vbCrLf
  100.    Next FileNum
  101.    
  102.    IdentifyFiles = ListFiles
  103. End Function
  104.  
  105. '------------------------------------------------------------------------------------
  106. ' Reads a ListItem object and returns a string of filenames separated
  107. ' by a line feed. When the user selects multiple files from the list
  108. ' and then clicks on Remove or Extract, the returned string will be used in
  109. ' the FilesToProcess property.
  110. '------------------------------------------------------------------------------------
  111. Public Function GetSelectedFiles(ListFiles As ListItems, UseBasePath As Boolean) As String
  112.     Dim counter             As Integer
  113.     Dim iNbSelected         As Integer
  114.     Dim sFilesToProcess     As String
  115.  
  116.     sFilesToProcess = ""
  117.     If ListFiles.Count > 0 Then
  118.         For counter = 1 To ListFiles.Count Step 1
  119.             If (ListFiles.Item(counter).Selected) Then
  120.                 If ListFiles.Item(counter) = "<dir>" Then
  121.                     sFilesToProcess = sFilesToProcess + ListFiles.Item(counter).SubItems(9) + "\" + vbCrLf
  122.                 ElseIf UseBasePath Then
  123.                     sFilesToProcess = sFilesToProcess + ListFiles.Item(counter).SubItems(9) + "\" + ListFiles.Item(counter) + vbCrLf
  124.                 Else
  125.                     sFilesToProcess = sFilesToProcess + ListFiles.Item(counter) + vbCrLf
  126.                 End If
  127.             End If
  128.         Next counter
  129.     End If
  130.     GetSelectedFiles = sFilesToProcess
  131. End Function
  132.  
  133. '------------------------------------------------------------------------------------
  134. ' This function opens up an 'Open File' Dialog to have the
  135. ' user select a zip file. Depending on the DialogType parameter,
  136. ' the behavior of the dialog is different.
  137. '
  138. ' This function will return the full path and filename of the
  139. ' selected zip file. If the Cancel button was used, then the
  140. ' function will return an empty string.
  141. '------------------------------------------------------------------------------------
  142. Public Function SelectZipFile(DialogType As Integer) As String
  143.  
  144.    With frmMain.dlgSelectZip
  145.  
  146.       .FileName = ""
  147.       .Flags = cdlOFNFileMustExist + cdlOFNNoChangeDir + cdlOFNHideReadOnly
  148.       .Filter = "Zip files (*.zip)|*.zip|Self-extracting zip files (*.exe)|*.exe|All files (*.*)|*.*"
  149.       .MaxFileSize = 32000
  150.       
  151.       Select Case DialogType
  152.          Case OpenZip
  153.             .DialogTitle = "Open Zip File"
  154.             .Action = 1
  155.          Case NewZip
  156.             .Flags = cdlOFNOverwritePrompt + cdlOFNNoChangeDir + cdlOFNHideReadOnly
  157.             .DialogTitle = "New Zip File"
  158.             .Action = 2  ' Pretend we are saving a file. The new zip file is really only created when you start zipping files into it.
  159.          Case SelectBin
  160.             .FileName = ""
  161.             .Filter = "Self-extractor binary (*.bin)|*.bin|All files (*.*)|*.*"
  162.             .DialogTitle = "Select self-extractor binary"
  163.             .Action = 1
  164.         Case ChooseFiles
  165.             .FileName = "*.*"
  166.             .DialogTitle = "Select files to process"
  167.             .Flags = 0
  168.             .Flags = cdlOFNFileMustExist + cdlOFNNoChangeDir + cdlOFNHideReadOnly + cdlOFNExplorer + cdlOFNAllowMultiselect + cdlOFNLongNames
  169.             .Filter = "All Files|*.*"
  170.             .Action = 1
  171.       End Select
  172.  
  173.       SelectZipFile = .FileName
  174.    End With
  175.    
  176. End Function
  177.  
  178. '------------------------------------------------------------------------------------
  179. ' This function prevents the user from entering caracters in a field. It's
  180. ' used with dates and numerical values controls.
  181. '------------------------------------------------------------------------------------
  182. Public Function ValidateNumbers(key As Integer) As Integer
  183.     Select Case key
  184.     Case 8, Asc("0") To Asc("9")        ' The 8th character is the Backspace key
  185.         ValidateNumbers = key
  186.     Case Else
  187.         ValidateNumbers = 0
  188.     End Select
  189. End Function
  190.  
  191. '------------------------------------------------------------------------------------
  192. ' Search backward in a string for a character
  193. '------------------------------------------------------------------------------------
  194. Public Function InStrRev(sString As String, sChar As String)
  195.     Dim i As Integer
  196.     
  197.     For i = Len(sString) To 1 Step -1
  198.         If Mid(sString, i, 1) = sChar Then
  199.             InStrRev = i
  200.             Exit Function
  201.         End If
  202.     Next i
  203.     
  204.     InStrRev = 0
  205. End Function
  206.